//
// Created by jsjxsy on 2022/7/15.
//
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
typedef struct Student {
  char *name;
  int age;
} Student;

int cmp_by_age(const void *a, const void *b) {
  return ((Student *) a)->age - ((Student *) b)->age;
}

int main(void) {
  Student students[3] = {
      {.name="zhangmazi", .age=50},
      {.name="tangshiye", .age=30},
      {.name="huangsilang", .age=40}
  };
  printf("排序之前的列表：\n");
  for (int n = 0; n < 3; n++) {
    printf("{name = %s, age = %d}\n", students[n].name, students[n].age);
  }
  puts("\n");
  qsort(students, 3, sizeof(Student), cmp_by_age);
  printf("排序之后的列表：\n");
  for (int n = 0; n < 3; n++) {
    printf("{name = %s, age = %d}\n", students[n].name, students[n].age);
  }
  return 0;
}
